package testing.dataBase;

import org.h2.jdbcx.JdbcConnectionPool;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;

public class DataBaseConnectionPool {
        private static JdbcConnectionPool cp = createPool();
    public static Connection getConnection()  throws SQLException
    {
        System.out.println("creating connection!");
        Connection connection = cp.getConnection();
        System.out.println("cp.getActiveConnections() = " + cp.getActiveConnections());
        return connection;
    }
     protected static JdbcConnectionPool createPool(){
        return JdbcConnectionPool.create("jdbc:h2:~/testingSystem", "sa", "");
    }
     public static void silentClose(Statement myStat) {
        if (myStat != null) {
            try {
                myStat.close();
            } catch (SQLException e) {
                //  ignored or reported to log4j with debug level
            }
        }
    }
    /*public static void silentClose(PreparedStatement preStat)
    {
        if (preStat != null) {
            try {
                preStat.close();
            } catch (SQLException e) {
                //  ignored or reported to log4j with debug level
            }
        }
    } */
    public static void silentClose(Connection conn) {
        System.out.println("destroying connection!");

        if (conn != null) {
            try {
                conn.close();
            } catch (SQLException e) {
                //  ignored or reported to log4j with debug level
            }
        }
    }


}

